package java44th.group.service.admin.feedback;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java44th.group.bean.common.BasePageInfo;
import java44th.group.bean.common.CommonData;
import java44th.group.bean.po.MarketFeedback;
import java44th.group.bean.po.MarketFeedbackExample;
import java44th.group.mapper.MarketFeedbackMapper;
import java44th.group.mapper.MarketSearchHistoryMapper;
import java44th.group.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ProjectName project-second
 * @Descriptiom TODO
 * @Aurhor: 蔡文强
 * @Since: 2022/10/12 21:32
 */
@Service
public class FeedbackServiceImpl implements FeedbackService{

    @Autowired
    MarketFeedbackMapper marketFeedbackMapper;

    @Override
    public CommonData<MarketFeedback> list(BasePageInfo basePageInfo, String username, Integer id) {
        PageHelper.startPage(basePageInfo.getPage(),basePageInfo.getLimit());

        MarketFeedbackExample example = new MarketFeedbackExample();
        example.getOrderByClause(basePageInfo.getSort()+" "+basePageInfo.getOrder());
        MarketFeedbackExample.Criteria criteria = example.createCriteria();
        if(!StringUtil.isEmpty(username)){
            criteria.andUsernameLike("%" + username +"%");
        }
        if(id!=null){
            criteria.andIdEqualTo(id);
        }
        List<MarketFeedback> marketFeedbacks = marketFeedbackMapper.selectByExample(example);

        PageInfo<MarketFeedback> marketFeedbackPageInfo = new PageInfo<>(marketFeedbacks);

        return CommonData.data(marketFeedbackPageInfo);
    }
}
